package com.generator.controller;

import com.generator.DTO.LoginDTO;
import com.generator.entity.UserEntity;
import com.generator.service.SysUserService;
import com.generator.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2023/11/19 10:17
 */
@Tag(name = "用户服务")
@RestController
@RequestMapping("user")
@CrossOrigin
public class AdminController {
    @Autowired
    private SysUserService sysUserService;

    @Operation(summary = "测试接口")
    @GetMapping("test")
    public String test(){
        return "password";
    }

    @Operation(summary = "登陆")
    @PostMapping("login")
    public Result login(@RequestBody LoginDTO user){
        return sysUserService.login(user);
    }

    @Operation(summary = "注册")
    @PostMapping("register")
    public Result register(@RequestBody LoginDTO user){
        return sysUserService.register(user);
    }

    @PostMapping("getByUsername")
    @Operation(summary = "根据用户名获取信息")
    public Result getByUsername(@RequestParam("username") String username){
        System.out.println("远程调用成功");
        UserEntity user = sysUserService.getByUsername(username);
        return new Result().ok(user);
    }
    @GetMapping("/captcha")
    @Operation(summary = "验证码")
    public void getArticle(HttpServletResponse response, @Param("key") String key){
        System.out.println(123);
        sysUserService.getArticle(response, key);
    }
}
